package com.zjj.distributed.zk.microservice.consumer.controller;

import com.zjj.distributed.zk.microservice.consumer.entity.OrderEntity;
import com.zjj.distributed.zk.microservice.consumer.service.OrderService;
import com.zjj.lbw.common.bean.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhanglei.zjj
 * @description Order服务mvc层
 * @date 2023/6/22 18:18
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @RequestMapping(value = "/findOrderByUserId/{id}")
    public R findOrderByUserId(@PathVariable("id") Integer userId) {
        // 模拟异常
        if(userId==5){
            throw new IllegalArgumentException("非法参数异常");
        }

        log.info("根据userId:"+userId+"查询订单信息");
        List<OrderEntity> orderEntities = orderService.listByUserId(userId);
        return R.ok().put("orders", orderEntities);
    }
}
